package com.itheima.d10_fight_landowner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 目标：应用Collections常用方法
 */
public class Test {

    public static void main(String[] args) {
        //1.制作一副扑克牌
        List<Card>  allCards = new ArrayList<>();
        //定义花色/点数的数组
        String[] colors = {"♦", "♣", "♥", "♠"};
        String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        int size = 0; //设置牌的大小
        //外层循环：遍历点数
        for (String point : points) {
            //内层循环：遍历花色
            size++;
            for (String color : colors) {
                //制作一张牌
                Card card = new Card(color, point, size);
                //添加牌盒
                allCards.add(card);
            }
        }

        //添加大小王
        allCards.add(new Card("🃏", "", 888));
        allCards.add(new Card("🤡", "", 666));
        System.out.println("制作完毕："+allCards);

        //2.洗牌
        Collections.shuffle(allCards);
        System.out.println("洗牌完毕："+allCards);

        //3.发牌
        List<Card> yeGeGe = new ArrayList<>();
        List<Card> yuGeGe = new ArrayList<>();
        List<Card> kangGeiGei = new ArrayList<>();
        List<Card> diPai = new ArrayList<>();

        for (int i = 0; i < allCards.size() - 3; i++) {
            if (i % 3 == 0) {
                yeGeGe.add(allCards.get(i));
            } else if (i % 3 == 1) {
                yuGeGe.add(allCards.get(i));
            } else {
                kangGeiGei.add(allCards.get(i));
            }
        }
                               //起始位置，结束位置（不包含最后）
        diPai = allCards.subList(allCards.size()-3, allCards.size());


        //4.看牌
        System.out.println("玩家1的牌："+yeGeGe);
        System.out.println("玩家2的牌："+yuGeGe);
        System.out.println("玩家3的牌："+kangGeiGei);
        System.out.println("底牌："+diPai);

        //5.（理牌）
        Collections.sort(yeGeGe,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(yuGeGe,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(kangGeiGei,(c1,c2)->c1.getSize()-c2.getSize());

        System.out.println("===码牌===");
        System.out.println("玩家1的牌："+yeGeGe);
        System.out.println("玩家2的牌："+yuGeGe);
        System.out.println("玩家3的牌："+kangGeiGei);
        System.out.println("底牌："+diPai);

        //6.抢地主
        kangGeiGei.addAll(diPai);

        //7.地主拿底牌+理牌
        Collections.sort(kangGeiGei,(c1,c2)->c1.getSize()-c2.getSize());


        System.out.println("=====最终的手牌=============");
        System.out.println("玩家1的牌："+yeGeGe);
        System.out.println("玩家2的牌："+yuGeGe);
        System.out.println("玩家3的牌："+kangGeiGei);
    }
}
